﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace YanZhiwei.DotNet3._5.Utilities.Base
{
    /// <summary>
    /// ConditionalIEnumerableSelector
    /// </summary>
    /// <typeparam name="T">泛型</typeparam>
    public class ConditionalIEnumerableSelector<T>
    {
        #region 构造函数
        public readonly IEnumerable<T> source;
        public readonly bool condition;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="csource">IEnumerable</param>
        /// <param name="ccondition">成立条件</param>
        public ConditionalIEnumerableSelector(IEnumerable<T> csource, bool ccondition)
        {
            this.source = csource;
            this.condition = ccondition;
        }
        #endregion
        #region ThenWhere
        /// <summary>
        /// ThenWhere
        /// </summary>
        /// <param name="keySelertor">委托</param>
        /// <returns>IEnumerable</returns>
        public IEnumerable<T> ThenWhere(Func<T, bool> keySelertor)
        {
            return condition == true ? source.Where(keySelertor) : source;
        }
        #endregion 

    }
}
